# -*- coding: utf-8 -*-
#from __future__ import unicode_literalsfrom django.shortcuts import render

from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt

from live_api import pili
from live_api.tools.Output_Helper import *
from live_api.tools.constant import *
import live_api.tools.utils_file as ufile
import os
import random
import time
import sys

reload(sys)
sys.setdefaultencoding("utf-8")


def env(key):
    if key in os.environ:
        return os.environ[key]
    else:
        return ""


# 获取礼物列表
@csrf_exempt
def gift_list(request):
    ret = ReturnJ()
    db =DB.getDB()
    try:
        # 房间基本信息
        sql = "select * from gift"
        n, rows = db.query(sql)
        # print rows[0]
        ret.giftlist = out_farmat_gift(rows)
        # ret.giftlist = rows[0]
        ret.msg = "成功"

    except Exception, e:
        ret.code = 1010
        ret.msg = str(e)
    res = HttpResponse(ret.toJson())
    res["Access-Control-Allow-Origin"] = "*"
    res["Access-Control-Allow-Methods"] = "POST, GET, OPTIONS"
    res["Access-Control-Max-Age"] = "1000"
    res["Access-Control-Allow-Headers"] = "*"
    return res


# 获取礼物
@csrf_exempt
def gift_info(request,id):
    ret = ReturnJ()
    db =DB.getDB()
    try:
        ret.gift_info = get_gift_info(id)
        ret.msg = "成功"

    except Exception, e:
        ret.code = 1010
        ret.msg = str(e)
    return HttpResponse(ret.toJson())
